package com.example.demo.base;

import com.google.common.collect.Maps;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.Map;

@Controller
public class BaseController {

    private Map<String, Object> result(String code, String message, Object model) {
        Map<String, Object> result = Maps.newHashMap();
        result.put("code", code);
        result.put("message", message);
        result.put("model", model);
        return result;
    }

    protected Map<String, Object> fail(String message) {
        return this.result("10001", message, null);
    }

    protected Map<String, Object> success(String message) {
        return this.result("200", message, null);
    }

    protected Map<String, Object> success() {
        return this.result("200", "成功", null);
    }

    protected Map<String, Object> success(Object model) {
        return this.result("200", "成功", model);
    }

    protected Map<String, Object> success(String message, Object model) {
        return this.result("200", message, model);
    }
}
